<?php
# this file will contain interface functions to create set timeline page

function i_set_timeline(){
	$html = '';
	
	$dateArr = c_get_time_curr_date();
	$date = $dateArr['year'].'-'.$dateArr['month'].'-'.$dateArr['day'];
	$hours = c_get_free_times($date);
	
	$html .= '<div class="wrapper">'.
				'<div class ="header"></div>'.
				'<div class="mainPage">'.
					'<h2 style="margin-left:350px;">Set timeline</h2>'.
					'<form method="post" action="php/core/Set_timeline/p_set_timeline.php">'.
	//					'<div>Format: &nbsp;&nbsp;<b>yyyy-mm-dd</b></div>'.
						'Date: <input type="text" name="date" value="'.$date.'"/><input type="submit" name="Show" value="Show" style="margin-left:5px; width:50px"><br/><br/>'.
						'Timeline for <b>'.$date.'</b><br/>'.
						'<table>'.
							'<tr>';
	$ci = 25; // number of hours +1
	for($i=0;$i<$ci;$i++){
		$html .=				'<td class="time_style">'.$i.'</td>';
	}
	$html .= 				'</tr>'.
							'<tr>';
	for($i=0;$i<$ci-1;$i++){ // -1 because we don't need checkbox after 24 number
		$checked = ''; // by default not checked
		if(in_array(strval($i), $hours)) $checked = 'checked';
		$html .=				'<td class="time_style cell_center"><input type="checkbox" name="time[]" value="'.$i.'" '.$checked.'/></td>';
	}
	$html .=				'</tr>'.
						'</table>'.
						'<br/>'.
						'<input type="submit" name="Set" value="Set" style="width:50px"/>'.
					'</form>'.
				'</div>'.
			'</div>';
	return $html;
}

# function will return array with times that is free for given day.
function c_get_free_times($date){
	$user_id = $_SESSION['user_id'];
	$query = "SELECT HOUR FROM timetable WHERE DATE = '$date' AND USER_ID=$user_id ORDER BY HOUR";
	$result = c_db_query($query);

	$hours = array();
	
	if($result){
		
		while($row = mysql_fetch_array($result)) 
		{
			$hours[] = $row[0];
		}
	}
	return $hours;
}
?>